package com;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

/**
 * 菜单管理类
 * 1.主菜单：
 *          1.2.设置菜单；
 * 2.二级主菜单：
 *          2.1.单人游戏页面；
 *          2.2.网络登录页面：
 *                      2.2.1.网络游戏页面
 *                      2.2.2.账户注册页面
 */
public class Menu extends JPanel{

//    static Image back ;
//    static {
//        try {
//            back = ImageIO.read(new File("Texture\\bg.jpg"));
//        } catch (IOException e) {
//            e.printStackTrace();
//            System.out.println("棋子图片加载失败！");
//        }
//    }


//    ImageIcon b_back = new ImageIcon(getClass().getResource("src\\com\\img\\bg.jpg"));

    //一级菜单： 开始， 设置， 退出
    JFrame frame_1 = new JFrame();
    JPanel jp_1 = new JPanel();    //创建JPanel对象
    JButton btn_1_1 = new JButton("开 始");    //创建JButton对象
    JButton btn_1_2 = new JButton("设 置");    //创建JButton对象
    JButton btn_1_3 = new JButton("退 出");    //创建JButton对象

    //二级菜单： 单人模式， 多人模式， 返回
    JPanel jp_2 = new JPanel();    //创建JPanel对象
    JFrame frame_2 = new JFrame();
    JButton btn_2_1 = new JButton("单 人 模 式");      //创建JButton对象
    JButton btn_2_2 = new JButton("多 人 模 式");      //创建JButton对象
    JButton btn_2_3 = new JButton("返 回");         //创建JButton对象

    //网络对战登录: 账号、密码框， 登录， 返回
    JPanel jp_3 = new JPanel();    //创建JPanel对象
    JFrame frame_3 = new JFrame();
    JTextField textField_3_1 = new JTextField();
    JPasswordField passwordField_3_1 = new JPasswordField();
    JLabel label_3_1 = new JLabel("账号:");
    JLabel label_3_2 = new JLabel("密码:");
    JButton btn_3_1 = new JButton("登 录");      //创建JButton对象
    JButton btn_3_2 = new JButton("返 回");      //创建JButton对象
    JButton btn_3_3 = new JButton("注册");

    //注册界面（~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~）
    JFrame frame_4 = new JFrame();
    JPanel jp_4 = new JPanel();    //创建JPanel对象
    JLabel label_4_1 = new JLabel("账号:");
    JLabel label_4_2 = new JLabel("密码:");
    JLabel label_4_3 = new JLabel("确认密码:");
    JTextField textField_4_1 = new JTextField();
    JPasswordField passwordField_4_1 = new JPasswordField();
    JPasswordField passwordField_4_2 = new JPasswordField();
    JButton btn_4_1 = new JButton("确 认");    //创建JButton对象
    JButton btn_4_2 = new JButton("退 出");    //创建JButton对象

    //设置菜单
    JFrame frame_5 = new JFrame();
    JPanel jp_5 = new JPanel();    //创建JPanel对象
    JButton btn_5_1 = new JButton("背 景");    //创建JButton对象
    JButton btn_5_2 = new JButton("音 乐");    //创建JButton对象
    JButton btn_5_3 = new JButton("返 回");    //创建JButton对象

    //单人游戏界面
    JFrame frame = new JFrame();
    JButton button_1 = new JButton("返 回");

/**
 *
 */
    public Menu(){

        Image Icon = null;
        try {
            Icon = ImageIO.read(new File("src\\com\\img\\r_m.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        //主菜单
        {
            frame_1.setSize(600, 800);
            frame_1.setTitle("中国象棋");
            frame_1.setLocationRelativeTo(null);
            frame_1.setIconImage(Icon);

            jp_1.setLayout(null);

            btn_1_1.setFocusPainted(false);
            btn_1_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_1.add(btn_1_1);
            btn_1_1.setBounds(200, 200, 200, 50);

            btn_1_2.setFocusPainted(false);
            btn_1_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_1.add(btn_1_2);
            btn_1_2.setBounds(200, 350, 200, 50);

            btn_1_3.setFocusPainted(false);
            btn_1_3.setFont(new Font("楷体",Font.BOLD,24));
            jp_1.add(btn_1_3);
            btn_1_3.setBounds(200, 500, 200, 50);

            frame_1.add(jp_1);
            frame_1.setVisible(true);
            frame_1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        //二级主菜单
        {
            frame_2.setSize(600, 800);
            frame_2.setTitle("中国象棋");
            frame_2.setLocationRelativeTo(null);
            frame_2.setIconImage(Icon);

            jp_2.setLayout(null);

            btn_2_1.setFocusPainted(false);
            btn_2_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_2.add(btn_2_1);
            btn_2_1.setBounds(200, 200, 200, 50);

            btn_2_2.setFocusPainted(false);
            btn_2_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_2.add(btn_2_2);
            btn_2_2.setBounds(200, 350, 200, 50);

            btn_2_3.setFocusPainted(false);
            btn_2_3.setFont(new Font("楷体",Font.BOLD,24));
            jp_2.add(btn_2_3);
            btn_2_3.setBounds(200, 500, 200, 50);

            frame_2.add(jp_2);
            frame_2.setVisible(false);
            frame_2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        //登陆界面
        {
            frame_3.setSize(600, 800);
            frame_3.setTitle("登录");
            frame_3.setLocationRelativeTo(null);
            frame_3.setIconImage(Icon);

            jp_3.setLayout(null);

            label_3_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_3.add(label_3_1);
            label_3_1.setBounds(130,150,70,50);

            label_3_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_3.add(label_3_2);
            label_3_2.setBounds(130,300,70,50);

            jp_3.add(textField_3_1);
            textField_3_1.setBounds(150,200,300,30);

            jp_3.add(passwordField_3_1);
            passwordField_3_1.setBounds(150,350,300,30);

            btn_3_1.setFocusPainted(false);
            btn_3_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_3.add(btn_3_1);
            btn_3_1.setBounds(150, 500, 100, 50);

            btn_3_2.setFocusPainted(false);
            btn_3_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_3.add(btn_3_2);
            btn_3_2.setBounds(350, 500, 100, 50);

            btn_3_3.setFocusPainted(false);
            jp_3.add(btn_3_3);
            btn_3_3.setBounds(400, 400, 60, 40);

            frame_3.add(jp_3);
            frame_3.setVisible(false);
            frame_3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        //注册界面（~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~）
        {
            frame_4.setSize(600, 450);
            frame_4.setTitle("注册");
            frame_4.setLocationRelativeTo(null);
            frame_4.setIconImage(Icon);

            jp_4.setLayout(null);

            label_4_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_4.add(label_4_1);
            label_4_1.setBounds(130,0,70,50);

            label_4_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_4.add(label_4_2);
            label_4_2.setBounds(130,100,70,50);

            label_4_3.setFont(new Font("楷体",Font.BOLD,24));
            jp_4.add(label_4_3);
            label_4_3.setBounds(110,200,120,50);

            jp_4.add(textField_4_1);
            textField_4_1.setBounds(150,50,300,30);

            jp_4.add(passwordField_4_1);
            passwordField_4_1.setBounds(150,150,300,30);

            jp_4.add(passwordField_4_2);
            passwordField_4_2.setBounds(150,250,300,30);

            btn_4_1.setFocusPainted(false);
            btn_4_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_4.add(btn_4_1);
            btn_4_1.setBounds(150, 320, 100, 50);

            btn_4_2.setFocusPainted(false);
            btn_4_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_4.add(btn_4_2);
            btn_4_2.setBounds(350, 320, 100, 50);


            frame_4.add(jp_4);
            frame_4.setVisible(false);
            frame_4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        //设置菜单
        {
            frame_5.setSize(600, 800);
            frame_5.setTitle("游戏设置");
            frame_5.setLocationRelativeTo(null);
            frame_5.setIconImage(Icon);

            jp_5.setLayout(null);

            btn_5_1.setFocusPainted(false);
            btn_5_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_5.add(btn_5_1);
            btn_5_1.setBounds(200, 200, 200, 50);

            btn_5_2.setFocusPainted(false);
            btn_5_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_5.add(btn_5_2);
            btn_5_2.setBounds(200, 350, 200, 50);

            btn_5_3.setFocusPainted(false);
            btn_5_3.setFont(new Font("楷体",Font.BOLD,24));
            jp_5.add(btn_5_3);
            btn_5_3.setBounds(200, 500, 200, 50);

            frame_5.add(jp_5);
            frame_5.setVisible(false);
            frame_5.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        //单人游戏页面
        {
            frame.setSize(1200,955);
            frame.setLocationRelativeTo(null);                      //窗口置中显示
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   //关闭窗口时停止程序运行
            frame.setTitle("中国象棋");

            frame.setIconImage(Icon);
            MyPanel panel = new MyPanel();
            panel.setLayout(null);
            frame.add(panel);
            panel.mouseAction();
            panel.CreatQieces();

            button_1.setFocusPainted(false);
            button_1.setFont(new Font("楷体",Font.BOLD,24));
            panel.add(button_1);
            button_1.setBounds(1000, 800, 100, 50);
        }

    }

    public void clicked(){

        //主菜单
        {
            btn_1_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("开始");
                    frame_1.setVisible(false);
                    frame_2.setVisible(true);
                }
            });

            btn_1_2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("设置");
                    frame_1.setVisible(false);
                    frame_5.setVisible(true);
                }
            });

            btn_1_3.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("退出");
                    System.exit(0);
                }
            });
        }

        //二级主菜单
        {
            btn_2_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("单人");
                    frame_2.setVisible(false);
                    frame.setVisible(true);
                }
            });

            btn_2_2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("多人");
                    frame_2.setVisible(false);
                    frame_3.setVisible(true);
                }
            });

            btn_2_3.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("返回");
                    frame_2.setVisible(false);
                    frame_1.setVisible(true);
                }
            });
        }

        //登录页面
        {
            btn_3_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String password = new String(passwordField_3_1.getPassword());
                    if (textField_3_1.getText().equals("0") && password.equals("0")) {
                        System.out.println("登录");
                    }
                }
            });

            btn_3_2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("返回");
                    frame_3.setVisible(false);
                    frame_2.setVisible(true);
                }
            });

            btn_3_3.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("注册");
                    frame_4.setVisible(true);
                }
            });
        }

        //注册菜单
        {
            //注册接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            btn_4_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("确认注册");
                }
            });

            btn_4_2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("退出");
                    frame_4.setVisible(false);
                }
            });
        }

        //设置菜单
        {
            btn_5_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("背景");
                }
            });

            btn_5_2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("音乐");
                }
            });

            btn_5_3.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("返回");
                    frame_5.setVisible(false);
                    frame_1.setVisible(true);
                }
            });
        }

        //单人游戏页面
        {
            button_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("返回");
                    frame.setVisible(false);
                    frame_2.setVisible(true);
                }
            });
        }
    }

}
